package com.dingreading.cloud.ssxcx.util;


import com.dingreading.cloud.ssxcx.service.XcxHomeworkFilesTrackService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@RefreshScope
@Component
public class ClockingUtils {
    public static String privateBucket_subject = "mst-subject";
    @Resource
    private XcxHomeworkFilesTrackService xcxHomeworkFileTrackService;

    /**
     * 定时任务：每5天早上2点执行一次，删除课后作业未使用图片
     * "0 0 2 1/5 * ?" 解释:
     * - `0`: 秒 (在每分钟的第0秒)
     * - `0`: 分 (在每小时的第0分)
     * - `2`: 小时 (在凌晨2点)
     * - `1/5`: 每月的第1天开始，然后每隔5天执行一次 (即每月1号、6号、11号、16号、21号、26号、31号)
     * - `*`: 月 (每个月)
     * - `?`: 星期几 (不指定星期几，因为已经指定了日期)
     */
    /*@Scheduled(cron = "0 0 2 1/5 * ?")
    public void deleteOssUrl() {
        List<XcxHomeworkFilesTrack> tracks = xcxHomeworkFileTrackService.getDeleteUrls();
        if (CollectionUtils.isNotEmpty(tracks)){
            List<String> deleteByUrls = tracks.stream().map(XcxHomeworkFilesTrack::getUrl).distinct().collect(Collectors.toList());
            try {
                OSSClientUtil ossClientUtil = new OSSClientUtil();
                ossClientUtil.initOss();
                ossClientUtil.deleteFiles(privateBucket_subject, deleteByUrls);
                Date nowDatetime = DateUtil.getNowDatetime();
                tracks.forEach(track -> {
                    track.setStatus(3);
                    track.setCleanupTime(nowDatetime);
                });
                xcxHomeworkFileTrackService.updateBatch(tracks);
                System.out.println("每5天早上2点执行一次，删除课后作业未使用图片");
            } catch (Exception e) {
            }
        }
    }*/

}
